<template>
  <div>
    <!-- 添加按钮 -->
    <el-button type="primary" @click="add">添加</el-button>
    <!-- {{menu_Arr}} -->
    <el-table
      :data="menu_Arr"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      :tree-props="{children: 'children'}"
    >
      <el-table-column prop="id" label="菜单编号"></el-table-column>
      <el-table-column prop="title" label="菜单名称"></el-table-column>
      <el-table-column prop="icon" label="菜单图标">
        <template slot-scope="scope">
          <i :class="scope.row.icon"></i>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"></el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status===1">启用</el-button>
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="edit(scope.row.id)">编辑</el-button>
          <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import {reqmenudelete} from "../../http/api";
import {successAlert} from "../../utils/alert";
export default {
  computed: {
    ...mapGetters({
        menu_Arr:"menu_Arr"
    })
  },
  activated() {
    this.set_menuArr();
  },
  methods: {
    ...mapActions({
        set_menuArr:"set_menuArr"
    }),
    // 2.2 点了添加
    add() {
      this.$router.push('/menu/add')
    },
    // 2.7 点了编辑
    edit(id) {
      this.$router.push('/menu/edit/'+id)
    },
    del(id) {
      this.$confirm("你确定要删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          //点了确定
          reqmenudelete({
            id:id
          }).then(res=>{
            if(res.data.code===200){
              //弹成功
              successAlert(res.data.msg)
              //重新请求列表
              this.$router.go(0);
            }
          })
        })
        .catch(() => {
          //点了取消
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  }
};
</script>
<style scoped lang="less">
@import "../../less/index.less";
</style>